/**
 * Copyright 2019-2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <string>
#include <memory>
#include <map>
#include <utility>

#include "common/util/op_info_util.h"
#define private public
#define protected public
#include "ops_kernel_store/fe_ops_kernel_info_store.h"
#include "ops_store/ops_kernel_manager.h"

#include "graph/ge_tensor.h"
#include "fusion_manager/fusion_manager.h"
#include "ops_kernel_store/sub_ops_store.h"
#include "adapter/tbe_adapter/tbe_op_store_adapter.h"
#include "format_selector/manager/format_dtype_querier.h"

using namespace std;
using namespace testing;
using namespace fe;

using fe::FEOpsKernelInfoStore;
using fe::SubOpsStore;
using ge::GeTensorDesc;
using ge::GeShape;
using ge::AttrUtils;
using ge::Format;
using ge::DataType;
using ge::ConstGeTensorDescPtr;
using ge::GeTensorDescPtr;
using ge::OpDescPtr;
using ge::OpDesc;
using fe::InputOrOutputInfoPtr ;
using ge::GeAttrValue;
using std::vector;
using std::map;
using namespace ge;

//using FEOpsKernelInfoStorePtr = std::shared_ptr<fe::FEOpsKernelInfoStore>;
//using OpStoreAdapterManagerPtr_ = std::shared_ptr<fe::OpStoreAdapterManager>;
//OpStoreAdapterManagerPtr_ op_store_adapter_manager_ptr_;
//FEOpsKernelInfoStorePtr fe_ops_kernel_info_store_ptr;
//op_store_adapter_manager_ptr_= std::make_shared<fe::OpStoreAdapterManager>();
//fe_ops_kernel_info_store_ptr = std::make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);

using TbeOpStoreAdapterPtr = std::shared_ptr<TbeOpStoreAdapter>;
using FormatDtypeQuerierPtr = std::shared_ptr<FormatDtypeQuerier>;

enum TestIter {
    TEST_SUCCESS = 0,
    TEST_HAVE_ALL,        // have one "all" type for attr check
    TEST_ATTR_NOT_FOUND,  // can not found attr ATTR_NAME_STR in OpDesc
    TEST_NOT_SUPPORT_DATA_TYPE,  // exit not support ValueType
    TEST_CHECK_FAILED,    // have one not match iter (ATTR_NAME_FLOAT)
    TEST_INT,
    TEST_FLOAT,
    TEST_BOOL,
    TEST_STR,
    TEST_LIST_INT,
    TEST_LIST_FLOAT,
    TEST_LIST_BOOL,
    TEST_LIST_STR,
    TEST_LACK_OF_ATTR_INT
};

static const string ATTR_NAME_INT = "transposX";
static const string ATTR_NAME_FLOAT = "transposY";
static const string ATTR_NAME_STR = "attrStr";
static const string ATTR_NAME_BOOL = "attrBool";
static const string ATTR_NAME_LIST_INT = "attrListInt";
static const string ATTR_NAME_LIST_FLOAT = "attrListFloat";
static const string ATTR_NAME_LIST_STR = "attrListStr";
static const string ATTR_NAME_LIST_BOOL = "attrListBool";
static const string ATTR_NAME_DEFAULT = "attr_name_default";

class STEST_OP_KERNEL_INFO_STORE : public testing::Test{
  protected:
    static void SetUpTestCase() {
        cout << "STEST_OP_KERNEL_INFO_STORE SetUP" << endl;
    }
    static void TearDownTestCase() {
        cout << "STEST_OP_KERNEL_INFO_STORE TearDown" << endl;
    }
    // Some expensive resource shared by all tests.
    virtual void SetUp(){
        op_desc_ptr = make_shared<ge::OpDesc>();
        input0_desc_ptr = make_shared<ge::GeTensorDesc>();
        input1_desc_ptr = make_shared<ge::GeTensorDesc>();
        input2_desc_ptr = make_shared<ge::GeTensorDesc>();
        output0_desc_ptr = make_shared<ge::GeTensorDesc>();
        std::map<std::string, std::string> options;
		
        op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
        TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
        op_store_adapter_manager_ptr_->map_all_op_store_adapter_.emplace(std::make_pair("tbe_op_adapter", tbe_adapter_ptr));

        sub_ops_store_ptr = make_shared<fe::SubOpsStore>(op_store_adapter_manager_ptr_);
        sub_ops_store_ptr->SetSubStoreType("tbe-custom");
        FEOpsStoreInfo tbe_custom {
          2,
          "tbe-custom",
          EN_IMPL_CUSTOM_TBE,
          "./air/test/engines/nneng/st/testcase/ops_kernel_store/fe_config/tbe_custom_opinfo",
          ""};

        sub_ops_store_ptr->SetSubStoreInfo(tbe_custom);
        Status stu = sub_ops_store_ptr->InitializeSubStore(fe::AI_CORE_NAME);
        EXPECT_EQ(fe::SUCCESS, stu);
        sub_ops_store_ptr->init_flag_ = true;

        sub_ops_store_ptr_cce = make_shared<fe::SubOpsStore>(op_store_adapter_manager_ptr_);
        sub_ops_store_ptr_cce->SetSubStoreType("cce-custom");
        FEOpsStoreInfo cce_custom {
        1,
        "cce-custom",
        EN_IMPL_HW_CONSTANT_CCE,
        "./air/test/engines/nneng/st/testcase/ops_kernel_store/fe_config/cce_custom_opinfo",
        ""};
        sub_ops_store_ptr_cce->SetSubStoreInfo(cce_custom);
        stu = sub_ops_store_ptr_cce->InitializeSubStore(fe::AI_CORE_NAME);
        EXPECT_EQ(fe::SUCCESS, stu);
        sub_ops_store_ptr_cce->init_flag_ = true;
        Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = {tbe_custom, cce_custom};
        OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

        OpsKernelManager::Instance(AI_CORE_NAME).Initialize();
        fe_ops_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);
        fe_ops_store_ptr->init_flag_ = true;
        fe_ops_store_ptr->map_all_sub_store_info_.emplace(std::make_pair("cce-custom", sub_ops_store_ptr_cce));
        fe_ops_store_ptr->map_all_sub_store_info_.emplace(std::make_pair("tbe-custom", sub_ops_store_ptr));
        fe_ops_store_ptr->op_kernel_store_type_ = "FEOpsStore";
        op_desc_ptr->SetName("tbe_conv");
        op_desc_ptr->SetType("conv");
        ge::DataType set_dtype = ge::DT_FLOAT16;
        ge::Format set_format = ge::FORMAT_ND;
        std::vector<int64_t> shape_vec{256,256,512};
        ge::GeShape shape_desc = GeShape(shape_vec);

        input0_desc_ptr->SetDataType(set_dtype);
        input0_desc_ptr->SetFormat(set_format);
        input0_desc_ptr->SetShape(shape_desc);
        op_desc_ptr->AddInputDesc("x", input0_desc_ptr->Clone());

        std::vector<int64_t> shape_vec1{256,256,512};
        ge::GeShape shape_desc1 = GeShape(shape_vec1);
        input1_desc_ptr->SetDataType(set_dtype);
        input1_desc_ptr->SetFormat(set_format);
        input1_desc_ptr->SetShape(shape_desc1);
        op_desc_ptr->AddInputDesc("y", input1_desc_ptr->Clone());

        std::vector<int64_t> shape_vec2{256,256,512};
        ge::GeShape shape_desc2 = GeShape(shape_vec2);
        input2_desc_ptr->SetDataType(set_dtype);
        input2_desc_ptr->SetFormat(set_format);
        input2_desc_ptr->SetShape(shape_desc2);
        op_desc_ptr->AddInputDesc("x1", input2_desc_ptr->Clone());

        output0_desc_ptr->SetDataType(set_dtype);
        output0_desc_ptr->SetFormat(set_format);
        op_desc_ptr->AddOutputDesc("z", output0_desc_ptr->Clone());

        format_dtype_querier_ptr_ = std::make_shared<FormatDtypeQuerier>(op_store_adapter_manager_ptr_);
        cout << "A ops kernel info store stest set up" << endl;
    }
    virtual void TearDown(){
        cout << "A ops kernel info store stest is tearing down" << endl;
        sub_ops_store_ptr->FinalizeSubStore();
        sub_ops_store_ptr_cce->FinalizeSubStore();
        fe_ops_store_ptr->Finalize();
       // c_fe_ops_kernel_info_store_ptr.reset();

    }
    void set_op_desc_default_value (OpDescPtr &op_desc_ptr_t)
    {
        op_desc_ptr_t->SetName("tbe_conv");
        op_desc_ptr_t->SetType("conv");
    }

    void SetOpDescPtrAttrValue(TestIter test_iter, OpDescPtr desc_ptr)
    {
        if (test_iter == TEST_INT) {
            AttrUtils::SetInt(desc_ptr, ATTR_NAME_INT, 10);
        }else if (test_iter != TEST_LACK_OF_ATTR_INT) {
            AttrUtils::SetInt(desc_ptr, ATTR_NAME_INT, 1);
        }
        if (test_iter == TEST_FLOAT) {
            AttrUtils::SetFloat(desc_ptr, ATTR_NAME_FLOAT, 22.0);
        }else{
            AttrUtils::SetFloat(desc_ptr, ATTR_NAME_FLOAT, 2.0);
        }
        if (test_iter == TEST_BOOL) {
            AttrUtils::SetBool(desc_ptr, ATTR_NAME_BOOL, true);
        }else{
            AttrUtils::SetBool(desc_ptr, ATTR_NAME_BOOL, false);
        }
        if (test_iter == TEST_STR) {
            AttrUtils::SetStr(desc_ptr, ATTR_NAME_STR, "not_exist");
        }else{
            AttrUtils::SetStr(desc_ptr, ATTR_NAME_STR, "abc");
        }
        if (test_iter == TEST_LIST_INT) {
            AttrUtils::SetListInt(desc_ptr, ATTR_NAME_LIST_INT, {6,7,8});
        }else{
            AttrUtils::SetListInt(desc_ptr, ATTR_NAME_LIST_INT, {1,2,3});
        }
        if (test_iter == TEST_LIST_FLOAT) {
            AttrUtils::SetListFloat(desc_ptr, ATTR_NAME_LIST_FLOAT, {6.0, 7.0, 8.0});
        }else{
            AttrUtils::SetListFloat(desc_ptr, ATTR_NAME_LIST_FLOAT, {1.0, 2.0, 3.0});
        }
        if (test_iter == TEST_LIST_BOOL) {
            AttrUtils::SetListBool(desc_ptr, ATTR_NAME_LIST_BOOL, {true,false,true});
        }else{
            AttrUtils::SetListBool(desc_ptr, ATTR_NAME_LIST_BOOL, {true,true,true});
        }
        if (test_iter == TEST_LIST_STR) {
            AttrUtils::SetListStr(desc_ptr, ATTR_NAME_LIST_STR, {"aa", "bb", "cc"});
        }else{
            AttrUtils::SetListStr(desc_ptr, ATTR_NAME_LIST_STR, {"a", "b", "c"});
        }

    }
public:
    shared_ptr<fe::SubOpsStore> sub_ops_store_ptr;
    shared_ptr<fe::SubOpsStore>  sub_ops_store_ptr_cce;
    shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_store_ptr;
    shared_ptr<ge::GeTensorDesc> input0_desc_ptr;
    shared_ptr<ge::GeTensorDesc> input1_desc_ptr;
    shared_ptr<ge::GeTensorDesc> input2_desc_ptr;
    shared_ptr<ge::GeTensorDesc> output0_desc_ptr;
    shared_ptr<ge::OpDesc> op_desc_ptr;
    OpStoreAdapterManagerPtr op_store_adapter_manager_ptr_;
    FormatDtypeQuerierPtr format_dtype_querier_ptr_;
};

TEST_F(STEST_OP_KERNEL_INFO_STORE, initialize_succ){
    shared_ptr<SubOpsStore> sub_ops_store_ptr = make_shared<SubOpsStore>(op_store_adapter_manager_ptr_);
    sub_ops_store_ptr->SetSubStoreType("tbe-custom");
    FEOpsStoreInfo tbe_custom {
          2,
          "tbe-custom",
          EN_IMPL_CUSTOM_TBE,
          "./air/test/engines/nneng/st/testcase/ops_kernel_store/fe_config/tbe_custom_opinfo",
          ""};
    sub_ops_store_ptr->SetSubStoreInfo(tbe_custom);
    Status ret = sub_ops_store_ptr->InitializeSubStore(fe::AI_CORE_NAME);
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, initialize_twice){
    shared_ptr<SubOpsStore> sub_ops_store_ptr = make_shared<SubOpsStore>(op_store_adapter_manager_ptr_);
    map<string, string> options;
    sub_ops_store_ptr->SetSubStoreType("tbe-custom");
    FEOpsStoreInfo tbe_custom {
          2,
          "tbe-custom",
          EN_IMPL_CUSTOM_TBE,
          "./air/test/engines/nneng/st/testcase/ops_kernel_store/fe_config/tbe_custom_opinfo",
          ""};
    sub_ops_store_ptr->SetSubStoreInfo(tbe_custom);
    Status ret1 = sub_ops_store_ptr->InitializeSubStore(fe::AI_CORE_NAME);
    Status ret2 = sub_ops_store_ptr->InitializeSubStore(fe::AI_CORE_NAME);
    EXPECT_EQ(fe::SUCCESS, ret1);
    EXPECT_EQ(fe::SUCCESS, ret2);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, get_all_ops_kernel_info_succ){
    shared_ptr<map<string, ge::OpInfo>> infos = make_shared<map<string, ge::OpInfo>>();
    fe_ops_store_ptr->GetAllOpsKernelInfo(*(infos.get()));
    EXPECT_NE(false, infos->size());
    infos.reset();
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, get_one_op_kernel_info_ptr)
{
    string op_type = "conv";
    string op_not_exist = "relu";
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", op_type);
    OpKernelInfoPtr op_kernel_info_ptr1 = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", op_not_exist);
    EXPECT_EQ(nullptr, op_kernel_info_ptr1);
    EXPECT_NE(nullptr, op_kernel_info_ptr);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, get_high_prio_op_kernel_info_ptr)
{
    string op_type = "conv";
    string op_not_exist = "relu";
    OpKernelInfoPtr op_kernel_info_ptr;
    OpKernelInfoPtr op_kernel_info_ptr1;

    Status ret = fe_ops_store_ptr->GetHighPrioOpKernelInfoPtr(op_type, op_kernel_info_ptr);
    Status ret1 = fe_ops_store_ptr->GetHighPrioOpKernelInfoPtr(op_not_exist, op_kernel_info_ptr1);

    EXPECT_NE(nullptr, op_kernel_info_ptr);
    if(op_kernel_info_ptr != nullptr){
        EXPECT_EQ("conv", op_kernel_info_ptr->GetOpType());
    }

    EXPECT_EQ(fe::SUCCESS, ret);
    EXPECT_NE(fe::SUCCESS, ret1);

}

TEST_F(STEST_OP_KERNEL_INFO_STORE, set_lib_type_succ){
    sub_ops_store_ptr->SetSubStoreType(string("tbe-custom"));
    string lib_type;
    sub_ops_store_ptr->GetSubStoreType(lib_type);
    EXPECT_EQ(lib_type, "tbe-custom");
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, get_lib_type_succ){
    string lib_type;
    sub_ops_store_ptr->GetSubStoreType(lib_type);
    EXPECT_EQ(lib_type, "tbe-custom");
}


TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_supported_succ)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    SetOpDescPtrAttrValue(TEST_SUCCESS, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(true, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_supported)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    SetOpDescPtrAttrValue(TEST_SUCCESS, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(true, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_supported_lack_of_attr)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Do not initialize attr int for this op desc */
    SetOpDescPtrAttrValue(TEST_LACK_OF_ATTR_INT, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);

    if(op_kernel_info_ptr != nullptr) {
        std::string reason;
        bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
        EXPECT_EQ(false, ret);
    }
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_int_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set int value as 10, which is not supported  */
    SetOpDescPtrAttrValue(TEST_INT, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(op_kernel_info_ptr, nullptr);

    if(op_kernel_info_ptr != nullptr) {
        std::string reason;
        bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
        EXPECT_EQ(false, ret);
    }
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_float_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set float value as 22.0, which is not supported  */
    SetOpDescPtrAttrValue(TEST_FLOAT, op_desc_ptr_t);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(op_kernel_info_ptr, nullptr);
    if(op_kernel_info_ptr != nullptr) {
        std::string reason;
        bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
        EXPECT_EQ(false, ret);
    }
}
TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_str_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set string value as "not exist", which is not supported  */
    SetOpDescPtrAttrValue(TEST_STR, op_desc_ptr_t);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(op_kernel_info_ptr, nullptr);
    if(op_kernel_info_ptr != nullptr) {
        std::string reason;
        bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
        EXPECT_EQ(false, ret);
    }
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_bool_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set bool value as true, which is not supported  */
    SetOpDescPtrAttrValue(TEST_BOOL, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(false, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_supported_list_bool_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set list bool value as [true, false, true], which is not supported  */
    SetOpDescPtrAttrValue(TEST_LIST_BOOL, op_desc_ptr_t);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(false, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_supported_list_int_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set list int value as [6, 7, 8], which is not supported  */
    SetOpDescPtrAttrValue(TEST_LIST_INT, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(false, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_list_float_false)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set list float value as [6.0, 7.0, 8.0], which is not supported  */
    SetOpDescPtrAttrValue(TEST_LIST_FLOAT, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(false, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_attr_list_str_false)
{

    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set list string value as ["aa", "bb", "cc"], which is not supported  */
    SetOpDescPtrAttrValue(TEST_LIST_STR, op_desc_ptr_t);
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    EXPECT_EQ(false, ret);
}
TEST_F(STEST_OP_KERNEL_INFO_STORE, check_supported_succ)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    shared_ptr<ge::GeTensorDesc> input0_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  input1_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  input2_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  output0_desc_ptr = make_shared<ge::GeTensorDesc>();
    op_desc_ptr_t->SetName("tbe_conv");
    op_desc_ptr_t->SetType("conv");
    int64_t int_value = 1;
    float float_value = 2.0;
    bool bool_value = false;
    string str_value = "abc";
    vector<int64_t> int_vec{1, 2, 3};
    vector<int64_t> rint_vec;
    vector<float> float_vec{4.0, 5.0, 6.0};
    vector<float> rfloat_vec;
    vector<bool> bool_vec{false, true, true};
    vector<bool> rbool_vec;
    std::vector<string> str_vec{"a", "b", "c"};
    AttrUtils::SetInt(op_desc_ptr_t, "transposX", int_value);
    AttrUtils::SetFloat(op_desc_ptr_t, "transposY", float_value);
    AttrUtils::SetBool(op_desc_ptr_t,"attrBool", bool_value);
    AttrUtils::SetStr(op_desc_ptr_t,"attrStr", str_value);
    AttrUtils::SetListInt(op_desc_ptr_t, "attrListInt", int_vec);
    AttrUtils::SetListFloat(op_desc_ptr_t, "attrListFloat", float_vec);
    AttrUtils::SetListBool(op_desc_ptr_t, "attrListBool", bool_vec);
    AttrUtils::SetListStr(op_desc_ptr_t, "attrListStr", str_vec);

    ge::DataType set_dtype = ge::DT_FLOAT16;
    std::vector<int64_t> shape_vec{256,256,512};
    ge::GeShape shape_desc = GeShape(shape_vec);

    input0_desc_ptr->SetDataType(set_dtype);
    input0_desc_ptr->SetShape(shape_desc);
    input0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
    input0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
    op_desc_ptr_t->AddInputDesc("x", input0_desc_ptr->Clone());

    std::vector<int64_t> shape_vec1{256,256,512};
    ge::GeShape shape_desc1 = GeShape(shape_vec1);
    input1_desc_ptr->SetDataType(set_dtype);
    input1_desc_ptr->SetShape(shape_desc1);
    input1_desc_ptr->SetFormat(ge::FORMAT_NCHW);
    input1_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
    op_desc_ptr_t->AddInputDesc("y", input1_desc_ptr->Clone());

    std::vector<int64_t> shape_vec2{256,256,512};
    ge::GeShape shape_desc2 = GeShape(shape_vec2);
    input2_desc_ptr->SetDataType(set_dtype);
    input2_desc_ptr->SetShape(shape_desc2);
    input2_desc_ptr->SetFormat(ge::FORMAT_NCHW);
    input2_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
    op_desc_ptr_t->AddInputDesc("x1", input2_desc_ptr->Clone());

    output0_desc_ptr->SetDataType(set_dtype);
    output0_desc_ptr->SetShape(shape_desc);
    output0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
    output0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
    op_desc_ptr_t->AddOutputDesc("z", output0_desc_ptr->Clone());

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    std::string reason;
    bool ret = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), reason);
    string un_supported_reason;
    bool ret2 = fe_ops_store_ptr->CheckSupported(op_desc_ptr_t, un_supported_reason);

    EXPECT_EQ(true, ret);
    EXPECT_EQ(true, ret2);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_supported_shape_fail)
{
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    shared_ptr<ge::GeTensorDesc> input0_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  input1_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  input2_desc_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::GeTensorDesc>  output0_desc_ptr = make_shared<ge::GeTensorDesc>();
    op_desc_ptr_t->SetName("tbe_conv");
    op_desc_ptr_t->SetType("conv");
    int64_t int_value = 1;
    float float_value = 2.0;
    bool bool_value = false;
    string str_value = "abc";
    vector<int64_t> int_vec{1, 2, 3};
    vector<int64_t> rint_vec;
    vector<float> float_vec{4.0, 5.0, 6.0};
    vector<float> rfloat_vec;
    vector<bool> bool_vec{false, true, true};
    vector<bool> rbool_vec;
    std::vector<string> str_vec{"a", "b", "c"};
    AttrUtils::SetInt(op_desc_ptr_t, "transposX", int_value);
    AttrUtils::SetFloat(op_desc_ptr_t, "transposY", float_value);
    AttrUtils::SetBool(op_desc_ptr_t,"attrBool", bool_value);
    AttrUtils::SetStr(op_desc_ptr_t,"attrStr", str_value);
    AttrUtils::SetListInt(op_desc_ptr_t, "attrListInt", int_vec);
    AttrUtils::SetListFloat(op_desc_ptr_t, "attrListFloat", float_vec);
    AttrUtils::SetListBool(op_desc_ptr_t, "attrListBool", bool_vec);
    AttrUtils::SetListStr(op_desc_ptr_t, "attrListStr", str_vec);

    ge::DataType set_dtype = ge::DT_FLOAT16;
    std::vector<int64_t> shape_vec{256,256,512};
    ge::GeShape shape_desc = GeShape(shape_vec);

    input0_desc_ptr->SetDataType(set_dtype);
    input0_desc_ptr->SetShape(shape_desc);
    op_desc_ptr_t->AddInputDesc("x", input0_desc_ptr->Clone());

    std::vector<int64_t> shape_vec1{256,-1,512};
    ge::GeShape shape_desc1 = GeShape(shape_vec1);
    input1_desc_ptr->SetDataType(set_dtype);
    input1_desc_ptr->SetShape(shape_desc1);
    op_desc_ptr_t->AddInputDesc("y", input1_desc_ptr->Clone());

    std::vector<int64_t> shape_vec2{256,256,512};
    ge::GeShape shape_desc2 = GeShape(shape_vec2);
    input2_desc_ptr->SetDataType(set_dtype);
    input2_desc_ptr->SetShape(shape_desc2);
    op_desc_ptr_t->AddInputDesc("x1", input2_desc_ptr->Clone());

    output0_desc_ptr->SetDataType(set_dtype);
    output0_desc_ptr->SetShape(shape_desc);
    op_desc_ptr_t->AddOutputDesc("z", output0_desc_ptr->Clone());

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);

    string un_supported_reason;
    bool ret1 = fe_ops_store_ptr->CheckSupported(op_desc_ptr_t, un_supported_reason);
    EXPECT_EQ(false, ret1);
    un_supported_reason = "";
    bool ret2 = fe_ops_store_ptr->CheckSupported(op_desc_ptr_t, un_supported_reason);
    EXPECT_EQ(false, ret2);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_accuracy_supported_succ)
{
  shared_ptr<OpStoreAdapterManager> op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
  shared_ptr<FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);
  using TbeOpStoreAdapterPtr = std::shared_ptr<TbeOpStoreAdapter>;
  std::map<std::string, std::string> options;
  op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
  TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  op_store_adapter_manager_ptr_->map_all_op_store_adapter_.emplace(std::make_pair("tbe_op_adapter", tbe_adapter_ptr));
  fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);
  FEOpsStoreInfo tbe_custom {
      2,
      "tbe-custom",
      EN_IMPL_CUSTOM_TBE,
      "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_custom_opinfo",
      ""};

  vector<FEOpsStoreInfo> store_info;
  store_info.emplace_back(tbe_custom);
  Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
  OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

  fe_ops_kernel_info_store_ptr->Initialize(options);
  shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
  shared_ptr<ge::GeTensorDesc> input0_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  input1_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  input2_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  output0_desc_ptr = make_shared<ge::GeTensorDesc>();
  op_desc_ptr_t->SetName("tbe_conv");
  op_desc_ptr_t->SetType("conv");
  int64_t int_value = 1;
  float float_value = 2.0;
  bool bool_value = false;
  string str_value = "abc";
  vector<int64_t> int_vec{1, 2, 3};
  vector<int64_t> rint_vec;
  vector<float> float_vec{4.0, 5.0, 6.0};
  vector<float> rfloat_vec;
  vector<bool> bool_vec{false, true, true};
  vector<bool> rbool_vec;
  std::vector<string> str_vec{"a", "b", "c"};
  AttrUtils::SetInt(op_desc_ptr_t, "transposX", int_value);
  AttrUtils::SetFloat(op_desc_ptr_t, "transposY", float_value);
  AttrUtils::SetBool(op_desc_ptr_t,"attrBool", bool_value);
  AttrUtils::SetStr(op_desc_ptr_t,"attrStr", str_value);
  AttrUtils::SetListInt(op_desc_ptr_t, "attrListInt", int_vec);
  AttrUtils::SetListFloat(op_desc_ptr_t, "attrListFloat", float_vec);
  AttrUtils::SetListBool(op_desc_ptr_t, "attrListBool", bool_vec);
  AttrUtils::SetListStr(op_desc_ptr_t, "attrListStr", str_vec);

  ge::DataType set_dtype = ge::DT_FLOAT16;
  std::vector<int64_t> shape_vec{256,256,512};
  ge::GeShape shape_desc = GeShape(shape_vec);

  input0_desc_ptr->SetDataType(set_dtype);
  input0_desc_ptr->SetShape(shape_desc);
  input0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("x", input0_desc_ptr->Clone());

  std::vector<int64_t> shape_vec1{256,256,512};
  ge::GeShape shape_desc1 = GeShape(shape_vec1);
  input1_desc_ptr->SetDataType(set_dtype);
  input1_desc_ptr->SetShape(shape_desc1);
  input1_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input1_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("y", input1_desc_ptr->Clone());

  std::vector<int64_t> shape_vec2{256,256,512};
  ge::GeShape shape_desc2 = GeShape(shape_vec2);
  input2_desc_ptr->SetDataType(set_dtype);
  input2_desc_ptr->SetShape(shape_desc2);
  input2_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input2_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("x1", input2_desc_ptr->Clone());

  ge::DataType set_dtype2 = ge::DT_FLOAT;
  output0_desc_ptr->SetDataType(set_dtype2);
  output0_desc_ptr->SetShape(shape_desc);
  output0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  output0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddOutputDesc("z", output0_desc_ptr->Clone());

  OpKernelInfoPtr op_kernel_info_ptr;
  SubOpsStorePtr sub_ops_store_ptr = fe_ops_kernel_info_store_ptr->map_all_sub_store_info_["tbe-custom"];
  string un_supported_reason;
  op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
  bool ret1 = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), un_supported_reason);
  bool ret2 = fe_ops_kernel_info_store_ptr->CheckAccuracySupported(op_desc_ptr_t, un_supported_reason);
  int64_t is_check_supported = 1;
  is_check_supported = (is_check_supported << 63);
  ge::AttrUtils::SetInt(op_desc_ptr_t, IS_CHECK_SUPPORTED, is_check_supported);
  bool ret3 = fe_ops_kernel_info_store_ptr->CheckAccuracySupported(op_desc_ptr_t, un_supported_reason);
  EXPECT_EQ(true, ret1);
  EXPECT_EQ(true, ret2);
  EXPECT_EQ(false, ret3);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_accuracy_supported_failed1)
{
  shared_ptr<OpStoreAdapterManager> op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
  shared_ptr<FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);
  using TbeOpStoreAdapterPtr = std::shared_ptr<TbeOpStoreAdapter>;
  std::map<std::string, std::string> options;
  op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
  TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  op_store_adapter_manager_ptr_->map_all_op_store_adapter_.emplace(std::make_pair("tbe_op_adapter", tbe_adapter_ptr));
  fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_);
  FEOpsStoreInfo tbe_custom {
      2,
      "tbe-custom",
      EN_IMPL_CUSTOM_TBE,
      "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_custom_opinfo",
      ""};

  vector<FEOpsStoreInfo> store_info;
  store_info.emplace_back(tbe_custom);
  Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
  OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

  fe_ops_kernel_info_store_ptr->Initialize(options);
  shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
  shared_ptr<ge::GeTensorDesc> input0_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  input1_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  input2_desc_ptr = make_shared<ge::GeTensorDesc>();
  shared_ptr<ge::GeTensorDesc>  output0_desc_ptr = make_shared<ge::GeTensorDesc>();
  op_desc_ptr_t->SetName("tbe_conv");
  op_desc_ptr_t->SetType("conv");
  int64_t int_value = 1;
  float float_value = 2.0;
  bool bool_value = false;
  string str_value = "abc";
  vector<int64_t> int_vec{1, 2, 3};
  vector<int64_t> rint_vec;
  vector<float> float_vec{4.0, 5.0, 6.0};
  vector<float> rfloat_vec;
  vector<bool> bool_vec{false, true, true};
  vector<bool> rbool_vec;
  std::vector<string> str_vec{"a", "b", "c"};
  AttrUtils::SetInt(op_desc_ptr_t, "transposX", int_value);
  AttrUtils::SetFloat(op_desc_ptr_t, "transposY", float_value);
  AttrUtils::SetBool(op_desc_ptr_t,"attrBool", bool_value);
  AttrUtils::SetStr(op_desc_ptr_t,"attrStr", str_value);
  AttrUtils::SetListInt(op_desc_ptr_t, "attrListInt", int_vec);
  AttrUtils::SetListFloat(op_desc_ptr_t, "attrListFloat", float_vec);
  AttrUtils::SetListBool(op_desc_ptr_t, "attrListBool", bool_vec);
  AttrUtils::SetListStr(op_desc_ptr_t, "attrListStr", str_vec);

  ge::DataType set_dtype = ge::DT_FLOAT16;
  std::vector<int64_t> shape_vec{256,256,512};
  ge::GeShape shape_desc = GeShape(shape_vec);

  input0_desc_ptr->SetDataType(set_dtype);
  input0_desc_ptr->SetShape(shape_desc);
  input0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("x", input0_desc_ptr->Clone());

  std::vector<int64_t> shape_vec1{256,256,512};
  ge::GeShape shape_desc1 = GeShape(shape_vec1);
  input1_desc_ptr->SetDataType(set_dtype);
  input1_desc_ptr->SetShape(shape_desc1);
  input1_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input1_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("y", input1_desc_ptr->Clone());

  std::vector<int64_t> shape_vec2{256,256,512};
  ge::GeShape shape_desc2 = GeShape(shape_vec2);
  input2_desc_ptr->SetDataType(set_dtype);
  input2_desc_ptr->SetShape(shape_desc2);
  input2_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  input2_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddInputDesc("x1", input2_desc_ptr->Clone());

  output0_desc_ptr->SetDataType(set_dtype);
  output0_desc_ptr->SetShape(shape_desc);
  output0_desc_ptr->SetFormat(ge::FORMAT_NCHW);
  output0_desc_ptr->SetOriginFormat(ge::FORMAT_NCHW);
  op_desc_ptr_t->AddOutputDesc("z", output0_desc_ptr->Clone());

  OpKernelInfoPtr op_kernel_info_ptr;
  string un_supported_reason;

  SubOpsStorePtr sub_ops_store_ptr = fe_ops_kernel_info_store_ptr->map_all_sub_store_info_["tbe-custom"];
  op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
  bool ret1 = sub_ops_store_ptr->CheckAttrSupport(*(op_desc_ptr_t.get()), *(op_kernel_info_ptr.get()), un_supported_reason);
  bool ret2 = fe_ops_kernel_info_store_ptr->CheckAccuracySupported(op_desc_ptr_t, un_supported_reason);
  int64_t is_check_supported = 1;
  is_check_supported = (is_check_supported << 63);
  ge::AttrUtils::SetInt(op_desc_ptr_t, IS_CHECK_SUPPORTED, is_check_supported);
  bool ret3 = fe_ops_kernel_info_store_ptr->CheckAccuracySupported(op_desc_ptr_t, un_supported_reason);
  EXPECT_EQ(true, ret1);
  EXPECT_EQ(false, ret2);
  EXPECT_EQ(false, ret3);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_dtype_false)
{
    shared_ptr<ge::GeTensorDesc> input_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::OpDesc> op_desc_ptr_t = make_shared<ge::OpDesc>();
    set_op_desc_default_value(op_desc_ptr_t);
    /* Set list int value as [6, 7, 8], which is not supported  */
    SetOpDescPtrAttrValue(TEST_SUCCESS, op_desc_ptr_t);

    ge::DataType set_dtype = ge::DT_UINT64;
    ge::Format set_format = ge::FORMAT_ND;
    std::vector<int64_t> shape_vec{256,256,512};
    ge::GeShape shape_desc = GeShape(shape_vec);

    input_ptr->SetDataType(set_dtype);
    input_ptr->SetFormat(set_format);
    input_ptr->SetShape(shape_desc);
    op_desc_ptr_t->AddInputDesc("x", input_ptr->Clone());
    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("cce-custom", "conv");
    EXPECT_NE(nullptr, op_kernel_info_ptr);
    InputOrOutputInfoPtr input_info_ptr;
    op_kernel_info_ptr->GetInputInfoByName("x", input_info_ptr);

    map<string, vector<ge::Format>> support_formats;
    map<string, vector<ge::DataType>> support_data_types;
    Status get_format_dtype_status = format_dtype_querier_ptr_->GetSupportFormatDtype(op_kernel_info_ptr,
            *(op_desc_ptr_t.get()), support_formats, support_data_types);
    EXPECT_EQ(fe::SUCCESS, get_format_dtype_status);
    bool ret = sub_ops_store_ptr->CheckDtypeSupported(*(op_desc_ptr_t.get()), input_ptr, input_info_ptr,
                                                   support_data_types.at(input_info_ptr->GetUniqueName()));
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, finalize_succ){
    Status ret = fe_ops_store_ptr->Finalize();
    EXPECT_EQ(fe::SUCCESS, ret);
}

Status GetOpStoreInfoByImplTypeStubzz(Configuration *This, OpImplType op_impl_type, FEOpsStoreInfo& op_store_info)
{
  Status return_status = fe::SUCCESS;
  op_store_info.fe_ops_store_name = "tbe-custom";
  op_store_info.need_pre_compile = true;
  op_store_info.need_compile = true;
  op_store_info.op_impl_file_path = "";
  return return_status;
}

Status CompileOpStubzz(TbeOpStoreAdapter *This, ScopeNodeIdMap &fusion_nodes_map, map<int64_t, std::string>& json_file_map, std::vector<ge::NodePtr> &compile_failed_nodes,
                       const std::vector<ge::NodePtr> &to_del_nodes)
{
  json_file_map.emplace(make_pair(-1, "a.json"));
  return fe::SUCCESS;
}

Status QueryHighPrioOpImplTypeStubTbe1zz(FEOpsKernelInfoStore* This, const ge::OpDescPtr& op_desc_ptr, OpImplType &impl_type) {

  impl_type = EN_IMPL_CUSTOM_TBE;
  return fe::SUCCESS;
}

Status PreCompileOp_Stub(TbeOpStoreAdapter *This, vector<PreCompileNodePara> &compile_para_vec)
{
  return fe::SUCCESS;
}

Status GetOpStoreAdapterStubzz(OpStoreAdapterManager *This, const OpImplType &op_impl_type, OpStoreAdapterPtr &adapter_ptr)
{
  adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  return fe::SUCCESS;
}

static void CreateSpacesizeTwoOpGraph(ComputeGraphPtr graph) {
  OpDescPtr bn_op = std::make_shared<OpDesc>("batchnormal", "conv");
  OpDescPtr relu_op = std::make_shared<OpDesc>("relu", "conv");

  // add descriptor
  vector<int64_t> dims = {1,2,3,4};
  GeShape shape(dims);

  GeTensorDesc in_desc1(shape);
  in_desc1.SetFormat(FORMAT_NCHW);
  in_desc1.SetDataType(DT_FLOAT16);
  relu_op->AddInputDesc("x", in_desc1);

  GeTensorDesc out_desc1(shape);
  out_desc1.SetFormat(FORMAT_HWCN);
  out_desc1.SetDataType(DT_FLOAT16);
  relu_op->AddOutputDesc("y", out_desc1);

  GeTensorDesc in_desc2(shape);
  in_desc2.SetFormat(FORMAT_FRACTAL_Z);
  in_desc2.SetDataType(DT_FLOAT16);
  bn_op->AddInputDesc("x", in_desc2);

  GeTensorDesc out_desc2(shape);
  out_desc2.SetFormat(FORMAT_NHWC);
  out_desc2.SetDataType(DT_FLOAT16);
  bn_op->AddOutputDesc("y", out_desc2);

  NodePtr bn_node = graph->AddNode(bn_op);
  NodePtr relu_node = graph->AddNode(relu_op);

  GraphUtils::AddEdge(bn_node->GetOutDataAnchor(0), relu_node->GetInDataAnchor(0));
}

TEST_F(STEST_OP_KERNEL_INFO_STORE, check_format_nd_success)
{
    shared_ptr<ge::GeTensorDesc> input_ptr = make_shared<ge::GeTensorDesc>();
    shared_ptr<ge::OpDesc> test_op_desc_ptr = make_shared<ge::OpDesc>();
    SetOpDescPtrAttrValue(TEST_SUCCESS,test_op_desc_ptr);
    ge::DataType set_dtype = ge::DT_UINT64;
    ge::Format set_format = ge::FORMAT_ND;
    std::vector<int64_t> shape_vec{256,256,512};
    ge::GeShape shape_desc = GeShape(shape_vec);

    input_ptr->SetDataType(set_dtype);
    input_ptr->SetOriginFormat(set_format);
    input_ptr->SetFormat(set_format);
    input_ptr->SetShape(shape_desc);
    test_op_desc_ptr->AddInputDesc("x", input_ptr->Clone());

    SubOpsStorePtr sub_ops_store_ptr = fe_ops_store_ptr->map_all_sub_store_info_["tbe-custom"];
    OpKernelInfoPtr op_kernel_info_ptr1 = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "conv");
    InputOrOutputInfoPtr input_info_ptr1;
    op_kernel_info_ptr1->GetInputInfoByName("x", input_info_ptr1);

    map<string, vector<ge::Format>> support_formats;
    map<string, vector<ge::DataType>> support_data_types;
    Status get_format_dtype_status = format_dtype_querier_ptr_->GetSupportFormatDtype(op_kernel_info_ptr1,
            *(test_op_desc_ptr.get()), support_formats, support_data_types);
    EXPECT_EQ(fe::SUCCESS, get_format_dtype_status);
    bool ret1 = sub_ops_store_ptr->CheckFormatSupported(*(test_op_desc_ptr.get()), input_ptr, input_info_ptr1,
            support_formats.at(input_info_ptr1->GetUniqueName()));
    EXPECT_EQ(false, ret1);


    OpKernelInfoPtr op_kernel_info_ptr2 = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("tbe-custom", "K");
    InputOrOutputInfoPtr input_info_ptr2;
    op_kernel_info_ptr2->GetInputInfoByName("x", input_info_ptr2);
    get_format_dtype_status = format_dtype_querier_ptr_->GetSupportFormatDtype(op_kernel_info_ptr2,
            *(test_op_desc_ptr.get()), support_formats, support_data_types);
    EXPECT_EQ(fe::SUCCESS, get_format_dtype_status);
    bool ret2 = sub_ops_store_ptr->CheckFormatSupported(*(test_op_desc_ptr.get()),input_ptr,input_info_ptr2,
            support_formats.at(input_info_ptr2->GetUniqueName()));
    EXPECT_EQ(true, ret2);
}

//TEST_F(STEST_OP_KERNEL_INFO_STORE, set_dynamic_custom_op_store_info_succ)
//{
//  ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");
//  OpDescPtr op_desc_0 = std::make_shared<OpDesc>("data", "Data");
//  OpDescPtr op_desc_a = std::make_shared<OpDesc>("A", "Conv4D");
//  // add descriptor
//  vector<int64_t> dim(4, 4);
//  GeShape shape(dim);
//  GeTensorDesc out_desc(shape);
//  GeTensorDesc out_desc1(shape);
//
//  op_desc_0->AddOutputDesc(out_desc);
//  op_desc_a->AddInputDesc(out_desc);
//  op_desc_a->AddInputDesc(out_desc1);
//  op_desc_a->AddOutputDesc(out_desc);
//
//  NodePtr node_0 = graph->AddNode(op_desc_0);
//  NodePtr node_a = graph->AddNode(op_desc_a);
//
//  OpDescPtr const_op = std::make_shared<OpDesc>("const", "Const");
//  GeTensorDesc src_tensor_desc(GeShape({1, 1024, 256, 512}), ge::FORMAT_NHWC, ge::DT_FLOAT);
//  const_op->AddOutputDesc(src_tensor_desc);
//  const_op->AddInputDesc(src_tensor_desc);
//  auto const_node = graph->AddNode(const_op);
//
//  GraphUtils::AddEdge(node_0->GetOutDataAnchor(0), node_a->GetInDataAnchor(0));
//  GraphUtils::AddEdge(const_node->GetOutDataAnchor(0), node_a->GetInDataAnchor(1));
//
//  ge::AttrUtils::SetBool(node_a->GetOpDesc(), CUSTOM_OP_FLAG, true);
//  std::string op_store_path = "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/non_persistent_tbe_custom_opinfo/non_persistent_tbe_custom_opinfo.json";
//  ge::AttrUtils::SetStr(node_a->GetOpDesc(), CUSTOM_OP_IMPL_CONFIG_PATH, op_store_path);
//
//  Status ret = fe_ops_store_ptr->SetDynamicCustomOpStoreInfo(*graph);
//  EXPECT_EQ(fe::SUCCESS, ret);
//
//  FEOpsStoreInfo op_store_info1;
//  Configuration::Instance(fe_ops_store_ptr->GetFEOpsKernelInfoStoreName()).
//                        GetOpStoreInfoByImplType(EN_IMPL_NON_PERSISTENT_CUSTOM_TBE, op_store_info1);
//  OpKernelInfoPtr op_kernel_info_ptr1 = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType("non-persistent-tbe-custom",
//    "Conv4D");
//  EXPECT_NE(nullptr, op_kernel_info_ptr1);
//  std::string op_dsl_file_path1;
//  if (op_kernel_info_ptr1 != nullptr &&
//      !op_kernel_info_ptr1->GetOpImpPath().empty()) {
//    op_dsl_file_path1 = op_kernel_info_ptr1->GetOpImpPath();
//  } else {
//    op_dsl_file_path1 = op_store_info1.op_impl_file_path;
//  }
//  std::string path = "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/non_persistent_tbe_custom_opinfo/op_imply/";
//  char resoved_path[260] =  {0x00};
//  realpath(path.c_str(), resoved_path);
//  path = resoved_path;
//  EXPECT_EQ(path, op_dsl_file_path1);
//}
